<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <!-- <div class="indexTitle">楼幢管理</div> -->
                    <div class="contentsize">管理方式</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="80px" :inline="true" size="mini">
                    <el-form-item label="区属名称:">
                        <div style="width:190px">
                            <el-select v-model="form.qs" placeholder="请选择区属名称" clearable>
                                <el-option v-for="item in qslist" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <div style="width:190px">
                            <el-input v-model="form.fwdz" placeholder="请输入房屋地址"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="档案编号:">
                        <div style="width:190px">
                            <el-input v-model="form.dabh" placeholder="请输入档案编号"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="产权单位:">
                        <div style="width:190px">
                            <!-- <el-input v-model="form.cqdw" placeholder="请输入产权单位"></el-input> -->
                            <el-select v-model="form.cqdw" placeholder="请选择产权单位" style="width: 100%">
                                <el-option v-for="item in cqdwlist" :key="item.code" :label="item.name" :value="item.code">
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item label="承租人:">
                        <div style="width:190px">
                            <el-input v-model="form.czr" placeholder="请输入承租人"></el-input>
                        </div>
                    </el-form-item>
                    <el-form-item label="状态:">
                        <div style="width:190px">
                            <el-select v-model="form.zt" placeholder="请选择状态" clearable>
                                <el-option v-for="item in ztlist" :key="item.code" :label="item.name" :value="item.code">
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor" :row-style="tablerowColor"
                border>
                <el-table-column prop="dabh" label="档案编号" align="center" width="160"> </el-table-column>
                <el-table-column prop="fwdz" label="房屋地址" align="center">
                    <template slot-scope="scope">
                        <span style="font-weight: 700;color: #409ee1;">
                            {{ scope.row.fwdz }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column prop="cqdw" label="产权单位" align="center"> </el-table-column>
                <el-table-column prop="cb" label="产别" align="center" width="100"> </el-table-column>
                <el-table-column prop="jzmj" label="面积" align="center" width="80"> </el-table-column>
                <el-table-column prop="glfs" label="经营方式" align="center" width="100">
                    <template slot-scope="scope">
                        <span style="font-weight: 700;color: #19BE6B;">
                            {{ scope.row.glfs }}
                        </span>
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="zt" label="状态" align="center" width="80">
                    <template slot-scope="scope">
                        <span :style="getcolorred(scope.row.zt)">
                            {{ scope.row.zt }}
                        </span>
                    </template>
                </el-table-column> -->
                <el-table-column label="操作" width="160" align="center">
                    <template slot-scope="scope">
                        <router-link :to="{ name: 'wtjydetail', params: { id: scope.row.id, jyglid: scope.row.jyglid, type: form.type } }" style="padding-right: 12px">
                            <el-button type="text" size="small" v-if="scope.row.jyglid ? true : false">详情</el-button>
                        </router-link>
                        <router-link :to="{ name: 'wtjyadd', params: { id: scope.row.id, type: form.type } }">
                            <el-button type="text" size="small" v-if="scope.row.jyglid ? false : true">编辑</el-button>
                        </router-link>
                        <router-link
                            :to="{ name: 'wtjyedit', params: { id: scope.row.id, jyglid: scope.row.jyglid, type: form.type } }">
                            <el-button type="text" size="small" v-if="scope.row.jyglid ? true : false">编辑</el-button>
                        </router-link>
                        <!-- <el-button type="text" size="small" @click="deleteClick(scope.row)"
                            style="color: red">删除</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,prev, pager, next,jumper" :total="total" :current-page.sync="current"
                    :page-size="pageSize" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import { jygllist, projectdelete } from '@/api/index';
import valueList from '@/components/common/valueList.vue'
export default {
    name: 'wtjylist',
    data() {
        return {
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                cb: "",
                cqdw: "",
                create_name: "",
                create_name_id: "",
                create_time: "",
                current: 1,
                dabh: "",
                fwdz: "",
                glfs: "",
                id: "",
                jyglid: "",
                jzmj: "",
                pageSize: 10,
                qs: "",
                status_code: 0,
                type: this.$store.getters.gfdw == '房产经理部' ? '1' : '2',//1房间 2楼
                update_name: "",
                update_name_id: "",
                update_time: ""
            },
            qslist: valueList.qslist,//区属
            cqdwlist: valueList.cqdwlist,//产权单位
            tableData: [],
            ztlist: valueList.ztlist//状态
        };
    },
    components: {},
    computed: {
        // 判断变色
        getcolorred(zt) {
            console.log(zt);
            return (zt) => {
                if (zt == "已出租") {
                    return { color: "#19BE6B", fontWeight: 700 };
                } else {
                    return { color: "#409ee1", fontWeight: 700 };
                }
            };
        },
    },
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background-color: #f7f7f7;color:black;height: 54px;font-weight: 500;font-size:14px;font-variant:tabular-nums'
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;'
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.jygllist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.jygllist(this.form);
            console.log('搜索');
        },
        // 添加
        addnew() {
            this.$router.push({
                name: 'addproject',
                path: '/addproject'
            });
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    projectdelete(data).then((res) => {
                        if (res.code == 200) {
                            this.jygllist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 项目列表
        jygllist(data) {
            jygllist(data).then((res) => {
                // console.log('res',res)
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        }
    },
    mounted() {
        this.jygllist(this.form);
    }
};
</script>

<style scoped>
.container {
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}
</style>
